package com.sojpt.boot.controller.business;

import com.jfinal.aop.Before;
import com.jfinal.kit.Kv;
import com.jfinal.kit.Ret;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.SqlPara;
import com.sojpt.boot.controller.business.validator.LkyEvaluationValidator;
import com.sojpt.boot.ui.iview.IViewController;
import com.sojpt.kit.SoJLogKit;
import com.sojpt.model.DicPopedom;
import com.sojpt.model.LkyEvaluation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLOutput;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * Description: 本类用于成绩评定的添加
 * Created by SMW on 2020/3/27 16:50
 */
@RestController
@RequestMapping("/admin/lkyEvaluation/")
public class LkyEvaluationController extends IViewController {

    @Before(LkyEvaluationValidator.class)
    @PostMapping("save")
    public void save(){
        System.out.println("进入");
        DicPopedom dicPopedom = new DicPopedom();
        dicPopedom.setForwardAction("/admin/lkyEvaluation/save");
        LkyEvaluation lkyEvaluation = getModel(LkyEvaluation.class,"lkyEvaluation");
        lkyEvaluation.setId(UUID.randomUUID().toString().replace("-", ""));
        //创建时间
        lkyEvaluation.setCreationTime(new Date());
        //更新时间
        lkyEvaluation.setUpdateTime(new Date());
        if(lkyEvaluation.save()){
            renderJson(Ret.ok());
            dicPopedom.setPopedomName("添加成功");
        }else{
            renderJson(Ret.fail());
            dicPopedom.setPopedomName("添加失败");
        }
        SoJLogKit.writeLog(this, dicPopedom,getSessionUser());
    }

    @PostMapping("Assessment")
    public void  AssessmentofSelect(String sid){
        LkyEvaluation lkyEvaluation = getModel(LkyEvaluation.class,"lkyEvaluation");
        SqlPara sqlPara = Db.getSqlPara("lky_assessment.selectList", Kv.by("sid",sid));
//        Page<Record> page =Db.paginate(pageNumber(),pageSize(),sqlPara);
        Page<Record> page = Db.paginate(pageNumber(), pageSize(), sqlPara);
        renderJson(page);
    }

    @PostMapping("update")
    public void update(){
        DicPopedom dicPopedom = new DicPopedom();
        dicPopedom.setForwardAction("/admin/lkyEvaluation/update");
        LkyEvaluation lkyEvaluation = getModel(LkyEvaluation.class,"lkyEvaluation");
        //更新时间
        lkyEvaluation.setUpdateTime(new Date());
        if (lkyEvaluation.update()){
            renderJson(Ret.ok());
            dicPopedom.setPopedomName("修改成功");
        }else{
            renderJson(Ret.fail());
            dicPopedom.setPopedomName("修改失败");
        }
        SoJLogKit.writeLog(this,dicPopedom,getSessionUser());
    }
}
